local zhuiyi = fk.CreateSkill {

  name = "joy__zhuiyi",

  tags = { Skill.Compulsory, },

}



zhuiyi:addEffect(fk.Death, {
  name = "joy__zhuiyi",
  anim_type = "support",
  events = {fk.Death},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhuiyi.name, false, true)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(room.alive_players, Util.IdMapper)
    if data.damage and data.damage.from then
      table.removeOne(targets, data.damage.from.id)
    end
    local p = room:askForChoosePlayers(player, targets, 1, 1, "#joy__zhuiyi-choose", zhuiyi.name, true)
    if #p > 0 then
      event:setCostData(self, p[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    to:drawCards(3, zhuiyi.name)
    if to:isWounded() and not to.dead then
      room:recover{
        who = to,
        num = 1,
        recoverBy = player,
        skillName = zhuiyi.name
      }
    end
  end,
})

return zhuiyi